﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ListenMusic.Singer_ServiceReference;
using System.ServiceModel;
using ListenMusic.Models.ViewModel;
namespace ListenMusic.Models.Reposistory.Public
{
    public class SingerReposistory
    {
        SingerServiceClient singerClient;
        CountryReposistory _country;
        public SingerReposistory()
        {
            singerClient = new SingerServiceClient();
           
        }
        public List<Singer> getAllSinger_byCountry(int countryid)
        {
            try {
                Singer[] singer = singerClient.getAllSinger_byCountry(countryid);
                return singer.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public int getMaxID_Singer()
        {
            try
            {
                return singerClient.getMaxID_Singer();
            }
            catch (FaultException e) { throw e; }
        }
        public Singer checkSingerName(string singername)
        {
            try
            {
                Singer s = singerClient.checkSingerName(singername);
                return s;
            }
            catch (FaultException e) { throw e; }
        }
        public bool insertNewSinger(Singer singer)
        {
            try
            {
                return singerClient.insertNewSinger(singer);
            }
            catch (FaultException e) { throw e; }
        }
        public List<CountrySinger> getAllSinger_byCountry()
        {
            _country = new CountryReposistory();
            try
            {
                var cs = from c in _country.getAllCountry()
                         select new CountrySinger()
                         {
                             CountryID = c.CountryID,
                             CountryName = c.CountryName,
                             singer = getAllSinger_byCountry(c.CountryID)
                         };
                return cs.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public List<ViewSearch_SingerName> search_SingerName(string keyword)
        {
            try
            {
                ViewSearch_SingerName[] singer = singerClient.search_SongName(keyword);
                return singer.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public List<Singer> getAllSinger()
        {
            try
            {
                Singer[] singer = singerClient.getAllSinger();
                return singer.ToList();
            }
            catch (FaultException e) { throw e; }
        }
        public Singer getSinger_bySingerName(string singerName)
        {
            try
            {
                Singer singer = singerClient.getSinger_bySingerName(singerName);
                return singer;
            }
            catch (FaultException e) { throw e; }
        }
    }
}